package com.itheima.day07.ZuoYe.Zuoye5;

import java.util.*;

public class Test2 {
    public static void main(String[] args) {
        //1.创建56张牌，将56张牌添加到allcards集合中去
        String [] colors = {"♥","♠","♣","♦"};
        String [] numbers = {"3","4","5","6","7","8","9","10","J","Q","K","A","2"};
        List<Card> allcards = new ArrayList<>();
        for (int i = 0; i < colors.length; i++) {
            int count = 1;
            for (int j = 0; j < numbers.length; j++) {
                allcards.add(new Card(colors[i]+numbers[j], colors[i],count));
                count++;
            }
        }
        allcards.add(new Card("小王", "小王",50));
        allcards.add(new Card("大王", "大王",100));
        for (int i = 0; i < allcards.size(); i++) {
            System.out.println(allcards.get(i).getName());
        }
        //2.洗牌
        Collections.shuffle(allcards);
        //3.发牌
        List<Card> player1 = new ArrayList<>();
        List<Card> player2 = new ArrayList<>();
        List<Card> player3 = new ArrayList<>();
        List<Card> dipai = new ArrayList<>();
        for (int i = 0; i < allcards.size()-3; i++) {
            if(i%3==0){
                player1.add(allcards.get(i));
            }else if(i%3==1){
                player2.add(allcards.get(i));
            }else if(i%3==2){
                player3.add(allcards.get(i));
            }
        }
        for (int i = allcards.size()-3; i < allcards.size(); i++) {
            dipai.add(allcards.get(i));
        }
        //根据牌的大小排序
        Collections.sort(player1, new Comparator<Card>() {
            @Override
            public int compare(Card o1, Card o2) {
                return o1.getSize()-o2.getSize();
            }
        });
        Collections.sort(player2,( o1, o2) -> o1.getSize()-o2.getSize());
        Collections.sort(player3,(o1, o2) -> o1.getSize()-o2.getSize());
        //展示结果
        System.out.println("玩家1的牌：");
        for (int i = 0; i < player1.size(); i++) {
            System.out.print(player1.get(i).getName()+" ");
        }
        System.out.println();
        System.out.println("玩家2的牌：");
        for (int i = 0; i < player2.size(); i++) {
            System.out.print(player2.get(i).getName()+" ");
        }
        System.out.println();
        System.out.println("玩家3的牌：");
        for (int i = 0; i < player3.size(); i++) {
            System.out.print(player3.get(i).getName()+" ");
        }
        System.out.println();
        System.out.println("底牌：");
        for (int i = 0; i < dipai.size(); i++) {
            System.out.print(dipai.get(i).getName()+" ");
        }


    }
}
